//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.t2t.top.dyn;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TypeConvertor {
    private static Map<Class<?>, Class<?>> typeConverter = new HashMap();

    public TypeConvertor() {
    }

    public static Object convertFromString(Class<?> paramType, String paramValueStr) throws ParseException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        Object paramValue = null;
        Class bigType = (Class)typeConverter.get(paramType);
        if(bigType == String.class) {
            paramValue = paramValueStr;
        } else if(bigType == Character.class) {
            if(paramValueStr.length() > 0) {
                paramValue = Character.valueOf(paramValueStr.toCharArray()[0]);
            } else {
                paramValue = null;
            }
        } else if(bigType == Date.class) {
            SimpleDateFormat transformedMethod = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = transformedMethod.parse(paramValueStr);
            paramValue = date;
        } else {
            Method transformedMethod1 = bigType.getMethod("valueOf", new Class[]{String.class});
            paramValue = transformedMethod1.invoke((Object)null, new Object[]{paramValueStr});
        }

        return paramValue;
    }

    public static boolean isTypeSupported(Class<?> type) {
        return typeConverter.containsKey(type);
    }

    public static Class<?>[] convertFromTypeString(List<String> typeStrings) throws ClassNotFoundException {
        int size = typeStrings.size();
        Class[] types = new Class[size];

        for(int i = 0; i < size; ++i) {
            types[i] = Class.forName((String)typeStrings.get(i));
        }

        return types;
    }

    public static Object[] convertToMethodArgs(Class<?>[] types, List<String> parameterStringValues) throws Exception {
        int length = types.length;
        Object[] methodArgs = new Object[length];

        for(int i = 0; i < length; ++i) {
            methodArgs[i] = convertFromString(types[i], (String)parameterStringValues.get(i));
        }

        return methodArgs;
    }

    static {
        typeConverter.put(Boolean.TYPE, Boolean.class);
        typeConverter.put(Boolean.class, Boolean.class);
        typeConverter.put(Byte.TYPE, Byte.class);
        typeConverter.put(Byte.class, Byte.class);
        typeConverter.put(Short.TYPE, Short.class);
        typeConverter.put(Short.class, Short.class);
        typeConverter.put(Character.TYPE, Character.class);
        typeConverter.put(Character.class, Character.class);
        typeConverter.put(Integer.TYPE, Integer.class);
        typeConverter.put(Integer.class, Integer.class);
        typeConverter.put(Long.TYPE, Long.class);
        typeConverter.put(Long.class, Long.class);
        typeConverter.put(Float.TYPE, Float.class);
        typeConverter.put(Float.class, Float.class);
        typeConverter.put(Double.TYPE, Double.class);
        typeConverter.put(Double.class, Double.class);
        typeConverter.put(String.class, String.class);
        typeConverter.put(Date.class, Date.class);
    }
}
